Gentoo doesn't have ifup/ifdown; appropriate alternatives are defined in
xen-network-common.sh.
+
+sed
+---
+
+\s is not supported in regexps on Debian etch (sed 4.1.2), Ubuntu 4.10. We
+hand-craft character classes instead.
frob_iptable
fi
}
+
+
+##
+# ip_of interface
+#
+# Print the IP address currently in use at the given interface, or nothing if
+# the interface is not up.
+#
+function ip_of()
+{
+ ip addr show "$1" | sed -n 's/^.*inet \([0-9.]*\).*$/\1/p'
+}
+
+
+##
+# dom0_ip
+#
+# Print the IP address of the interface in dom0 through which we are routing.
+# This is the IP address on the interface specified as "netdev" as a parameter
+# to these scripts, or eth0 by default. This function will call fatal if no
+# such interface could be found.
+#
+function dom0_ip()
+{
+ local nd=${netdev:-eth0}
+ local result=$(ip_of "$nd")
+ if [ -z "$result" ]
+ then
+ fatal
+"$netdev is not up. Bring it up or specify another interface with " \
+"netdev=<if> as a parameter to $0."
+ fi
+ echo "$result"
+}
netmask=$netmask.$(( (($intmask & 0x0000FF00)) >> 8 ))
netmask=$netmask.$(( $intmask & 0x000000FF ))
-main_ip=$(ip addr show eth0 | sed -e '/inet /!d;s/^.*inet \([^\s*]\)\s.*$/\1/')
+main_ip=$(dom0_ip)
case "$command" in
online)